public class RotateRight {
    //旋转链表k个单位
    public ListNode rotateRight(ListNode head, int k) {
        if(head==null||head.next==null||k==0){
            return head;
        }
        int count = 0;
        ListNode cur = head;
        while(cur.next!=null){
            cur = cur.next;
            count++;
        }
        cur.next = head;
        int num = (count+1)-k%(count+1)-1;
        ListNode prev = head;
        ListNode newHead = head.next;
        while(num!=0){
            newHead = newHead.next;
            prev = prev.next;
            num--;
        }
        prev.next = null;
        return newHead;
    }
}
